package com.orange.off.cloud.cloudoff.utils;

import android.content.Context;
import android.view.View;
import android.view.inputmethod.InputMethodManager;

/**
 * 获取焦点键盘弹出/清空焦点键盘隐藏
 *
 * @author smile
 */
public class GetEditFocusable {
    public static GetEditFocusable getEditFocusable() {
        GetEditFocusable getEditFocusable = new GetEditFocusable();
        return getEditFocusable;
    }

    public void getFocusable(Context context, View v) {
        if (v.isFocusable()) {

        } else {
            v.setFocusable(true);
            v.setFocusableInTouchMode(true);
            v.requestFocus();
            InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.showSoftInput(v, InputMethodManager.RESULT_SHOWN);
            imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
        }

    }
    public void ClearEditFocusable(Context context,View v) {
        if (v.isFocusable()) {
            InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
        } else {
            InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
        }

    }

}
